package com.jiazhong.basic.shuxin.net;

import lombok.SneakyThrows;

import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class DemoC1 {

    @SneakyThrows
    public static void main(String[] args) {
        System.out.println("准备进行通信操作");
        // 服务端 指定端口号
        ServerSocket serverSocket = new ServerSocket(8888);
        System.out.println("开启了服务器," + serverSocket);
        // 开启一个通信端 socket套接字
        Socket socket = serverSocket.accept();
        System.out.println("通信端已经开启成功");
        // 发送内容
        OutputStream out = socket.getOutputStream();
        String message = "你好，DemoC2！我是DemoC1！";
        out.write(message.getBytes(StandardCharsets.UTF_8));
    }
}
